package com.broada.apm.service;

import java.util.HashMap;
import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import com.broada.apm.ajax.ApplicationResult;
import com.broada.apm.ajax.PerformanceResult;
import com.broada.apm.entity.ApplicationSystem;
import com.broada.apm.entity.Service;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

@Path("apm/applications")
@Api(value="apm/applications" , description = "应用系统相关的APIs")
@Produces(MediaType.APPLICATION_JSON)
public interface ApplicationService {
	/**
	 * 获取所有系统列表信息
	 * 
	 * @return
	 */
	@GET
	@ApiOperation(value = "获取所有系统列表信息")
	@Produces(MediaType.APPLICATION_JSON)
	public ApplicationResult queryApplications();

	/**
	 * 按照id获取单个系统列表信息
	 * 
	 * @param appId
	 * @return
	 */
	@GET
	@Path("/{appId}")
	@ApiOperation(value = "按照id获取单个系统列表信息")
	@Produces(MediaType.APPLICATION_JSON)
	public ApplicationResult queryApplication(
			@ApiParam(value = "应用系统id", required = true) @PathParam("appId") String appId, 
			@ApiParam(value = "用以区分交易模式和非交易模式，可为system或business", required = true) @QueryParam("panelId") String panelId);

	/**
	 * 添加系统名称和apdex
	 * 
	 * @param app
	 */
	@POST
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "修改应用系统基本配置信息")
	public ApplicationResult addApplicationNameAndApdex(
			@ApiParam(value = "提交的应用系统基本配置信息，提交形式类似于：{id: \"is73ly3n-1\", name: \"mysql\"}", required = true) HashMap<String, String> map);

	/**
	 * 删除系统
	 * 
	 * @param appId
	 */
	@DELETE
	@Path("/{appId}")
	@ApiOperation(value = "删除应用系统")
	@Produces(MediaType.APPLICATION_JSON)
	public ApplicationResult deleteApplicationById(@ApiParam(value = "应用系统id", required = true) @PathParam("appId") String appId);

	/**
	 * 修改系统名称和apdex
	 * @param map
	 */
	@PUT
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "添加应用系统基本配置信息")
	public ApplicationResult updateApplicationNameAndApdex(
			@ApiParam(value = "提交的应用系统基本配置信息，提交形式类似于：{id: \"is73ly3n-1\", name: \"mysql\"}", required = true) HashMap<String, String> map);

	/**
	 * 根据系统id添加拓扑图信息
	 * 
	 * @param applicationId
	 * @return
	 */
	@POST
	@Path("/{appId}/topology")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "根据系统id添加拓扑图信息")
	public ApplicationResult saveApplicationTopology(
			@ApiParam(value = "应用系统id", required = true) @PathParam("appId") String appId, 
			@ApiParam(value = "提交的应用系统实体", required = true) ApplicationSystem app);

	/**
	 * 根据系统id和节点id删除拓扑图中的节点
	 * 
	 * @param appId
	 *          系统id
	 * @param nodeIds
	 *          需要删除的节点id
	 * @return
	 */
	@DELETE
	@Path("/{appId}/topology/nodes")
	@ApiOperation(value = "根据系统id和节点id删除拓扑图中的节点")
	@Produces(MediaType.APPLICATION_JSON)
	public ApplicationResult deleteApplicationTopologyNodesByNodeIds(
			@ApiParam(value = "应用系统id", required = true) @PathParam("appId") String appId,
			@ApiParam(value = "拓扑图节点id", required = true) @QueryParam("ids") String nodeId);

	/**
	 * 拓扑图添加节点
	 * 
	 * @param list
	 *          节点信息
	 * @return
	 */
	@POST
	@Path("/{appId}/{panelId}/topology/nodes")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "拓扑图添加节点")
	public ApplicationResult saveApplicationTopologyNodes(
			@ApiParam(value = "应用系统id", required = true) @PathParam("appId") String appId, 
			@ApiParam(value = "添加的服务节点", required = true) List<Service> list, 
			@ApiParam(value = "用以区分交易模式和非交易模式，可为system或business", required = true) @PathParam("panelId") String panelId);

	/**
	 * 获取拓扑图添加的节点关系
	 * 
	 * @param appId
	 * @param nodeIds
	 * @return
	 */
	@GET
	@Path("/{appId}/topology/relations")
	@ApiOperation(value = "获取拓扑图添加的节点关系")
	@Produces(MediaType.APPLICATION_JSON)
	public ApplicationResult queryApplicationTopologyRelations(
			@ApiParam(value = "应用系统id", required = true) @PathParam("appId") String appId,
			@ApiParam(value = "拓扑节点id", required = true) @QueryParam("nodeIds") String nodeIds);

	@Path("/changeorder")
	@POST
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "调整应用系统显示顺序")
	public ApplicationResult changeOrder(
			@ApiParam(value = "应用系统id，提交形式类似于：{id1: \"it8i8mlm-1\", id2: \"iu8flurm-0\"}", required = true) HashMap<String, String> ids);
	
	/**
	 * 获取应用系统下所有的关键交易和节点及自身
	 * 
	 * @param appId
	 * @param nodeIds
	 * @return
	 */
	@GET
	@Path("/{appId}/baseResource/{panelId}")
	@ApiOperation(value = "获取应用系统下所有的关键交易和节点及自身")
	@Produces(MediaType.APPLICATION_JSON)
	public ApplicationResult queryAOSByAppId(
			@ApiParam(value = "应用系统id", required = true) @PathParam("appId") String appId, 
			@ApiParam(value = "用以区分交易模式和非交易模式，可为system或business", required = true) @PathParam("panelId") String panelId);
	
	/**
	 * 获取当前应用系统下所有的协议
	 * @param appId
	 * @return
	 */
	@GET
	@Path("/{appId}/protos")
	@ApiOperation(value = "获取当前应用系统下所有的协议")
	@Produces(MediaType.APPLICATION_JSON)
	public ApplicationResult queryProtocalByAppId(@ApiParam(value = "应用系统id", required = true) @PathParam("appId") String appId);
	
	/**
	 * 获取当前应用系统下所有节点
	 * @param appId
	 * @return
	 */
	@GET
	@Path("/{appId}/ips")
	@ApiOperation(value = "获取当前应用系统下所有节点")
	@Produces(MediaType.APPLICATION_JSON)
	public ApplicationResult queryIpsByAppId(@ApiParam(value = "应用系统id", required = true) @PathParam("appId") String appId);
	
	/**
	 * 获取交易总览页面的应用系统
	 * @param inOverview
	 * @return
	 */
	@GET
	@Path("/inOverview")
	@ApiOperation(value = "获取交易总览页面的应用系统")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult queryAppsInOverview(
			@ApiParam(value = "是否显示在交易总览页面上，true或false", required = true) @QueryParam("isOverview") boolean isOverview, 
			@ApiParam(value = "关键词", required = false) @QueryParam("keyWord") String keyWord,
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate, 
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate);
	
	/**
	 * 将业务系统放入交易总览页面或从交易总览页面删除
	 * @param appId
	 * @param application
	 */
	@PUT
	@Path("/fromOverview")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "将业务系统放入交易总览页面或从交易总览页面删除")
	public ApplicationResult appInOrOutOverview(
			@ApiParam(value = "isOverview：true为添加，false为删除，appIds：进行操作的应用系统的id，提交形式类似于：{isOverview: true, appIds: [\"it2cxakl-7\"]}", required = true) HashMap<String, Object> map);
	
	/**
	 * 保存交易总览页面上所有的应用系统
	 * @param appIds
	 * @return
	 */
	@PUT
	@Path("/save/inOverview")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "保存交易总览页面上所有的应用系统")
	public ApplicationResult saveAppsInOverview(@ApiParam(value = "需要保存的所有应用系统的id", required = true) List<String> appIds);
	
	/**
	 * 交易总览中改变应用系统顺序
	 * @param ids
	 * @return
	 */
	@POST
	@Path("/business/changeorder")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "调整交易总览页面应用系统显示顺序")
	public ApplicationResult businessChangeOrder(@ApiParam(value = "应用系统id，提交形式类似于：{id1: \"it8i8mlm-1\", id2: \"iu8flurm-0\"}", required = true) HashMap<String, String> ids);
	
}
